home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / misc / coding / dp_srccs / f-scape.asm < prev    next >
Encoding:
Assembly Source File  |  1996-12-08  |  16.0 KB  |  633 lines

  1. ────────────────────────────────────────────────────────────────────────────────
  2. ; plasmoid/deep/thc 1996:
  3. ; code by plasmoid/deep/thc
  4. ────────────────────────────────────────────────────────────────────────────────
  5. vsync        macro
  6.              local    @@vs1, @@vs2
  7.         mov    dx,03dah    ; ∙ retrace sync...
  8. @@vs1:        in    al,dx
  9.         test    al,8
  10.         jnz    @@vs1        ; ∙ while not in display do.
  11. @@vs2:        in    al,dx
  12.         test    al,8
  13.         jz    @@vs2        ; ∙ while in display do
  14. endm
  15. ────────────────────────────────────────────────────────────────────────────────
  16. .model small
  17. .stack 400
  18. .code
  19. .386
  20.         locals
  21. scrwidth     equ     80
  22. initheight    equ    00
  23. vgaseg        equ    0a000h
  24. ────────────────────────────────────────────────────────────────────────────────
  25. .startup
  26. c_site:        jmp    main
  27. info        db    "∙ code by plasmoid of deep ∙"
  28. ────────────────────────────────────────────────────────────────────────────────
  29. blendout        proc    near
  30.         mov     blendcount,00
  31.         mov     bdirection,00
  32.         jmp     blendit
  33. blendin:        mov     blendcount,00
  34.         mov     bdirection,3fh
  35. blendit:        mov     cx,3fh
  36. blending:       push    cx
  37.         call    blend
  38.         pop     cx
  39.         loop    blending
  40.         ret
  41. blendout        endp
  42. ────────────────────────────────────────────────────────────────────────────────
  43. blend           proc near
  44.         mov     si,offset vgapalette
  45.         mov     dx,03c8h               ; ∙ write to PEL port
  46.         mov     al,00h
  47.         out     dx,al
  48.         inc     dx
  49.  
  50.         mov     ah,blendcount
  51.         xor     ah,bdirection
  52.  
  53.         mov     cx,256
  54. @bchange:       lodsb
  55.         add     al,ah
  56.         cmp     al,3fh
  57.         jb      $+4
  58.         mov     al,3fh
  59.         out     dx,al
  60.         lodsb
  61.         add     al,ah
  62.         cmp     al,3fh
  63.         jb      $+4
  64.         mov     al,3fh
  65.         out     dx,al
  66.         lodsb
  67.         add     al,ah
  68.         cmp     al,3fh
  69.         jb      $+4
  70.         mov     al,3fh
  71.         out     dx,al
  72.         loop    @bchange
  73.         inc     blendcount
  74. @bskip:         ret
  75. blendcount      db      00
  76. bdirection      db      3fh
  77. blend           endp
  78.  
  79. ────────────────────────────────────────────────────────────────────────────────
  80. convert         proc    near
  81.         xor     bx,bx
  82. @@two:          mov     cx,bp           ; ∙ lg to cx
  83. @@one:          xor     dx,dx
  84.         mov     dl,ds:[si]      ; ∙ read from srce to dl
  85.         shl     dx,4
  86.         shr     dl,4
  87.         add     dh,select
  88.         mov     ds:[di],dh
  89.         inc     di
  90.         add     dl,select
  91.         mov     ds:[di],dl
  92.         inc     di
  93.         inc     si
  94.         loop    @@one
  95.         dec     ax              ; ∙ dec
  96.         jnz     @@two
  97.         ret
  98. select          db      00
  99. convert         endp
  100. ────────────────────────────────────────────────────────────────────────────────
  101. ega2vga         proc    near
  102.         mov     si,offset logo
  103.         mov     di,offset vgalogo
  104.         mov     ax,85
  105.         mov     bp,256/2
  106.         call    convert
  107.         ret
  108. ega2vga         endp
  109. ────────────────────────────────────────────────────────────────────────────────
  110. checkkey        proc    near
  111.         cmp byte ptr keystroke,01
  112.         je      escape
  113.         jmp     no
  114. escape:         jmp     exit
  115. no:             ret
  116. checkkey        endp
  117. ────────────────────────────────────────────────────────────────────────────────
  118. int_key         proc    near
  119.         cli
  120.         push    ax
  121.         in      al,60h
  122.         cmp     al,01                   ; ∙ escape
  123.         je      put
  124.         mov     cs:keystroke,00
  125.         jmp     none                    ; ∙ none
  126. put:            mov     cs:keystroke,al
  127. none:           in      al,61h
  128.         mov     ah,al
  129.         or      al,80h
  130.         out     61h,al
  131.         sti
  132.         mov     al,20h
  133.         out     20h,al
  134.         pop     ax
  135.         iret
  136. keystroke       db      00
  137. int_key         endp
  138. ────────────────────────────────────────────────────────────────────────────────
  139. initkeyboard    proc    near
  140.         cli
  141.         push    fs
  142.         xor     dx,dx
  143.         mov     fs,dx
  144.         mov     eax,fs:[9*4]
  145.         mov     oldint9,eax
  146.         mov     ax,cs
  147.         shl     eax,16
  148.         mov     ax,offset int_key
  149.         mov     fs:[9*4],eax
  150.         sti
  151.         pop     fs
  152.         ret
  153. initkeyboard    endp
  154. ────────────────────────────────────────────────────────────────────────────────
  155. killkeyboard    proc near
  156.         cli
  157.         push    fs
  158.         xor     dx,dx
  159.         mov     fs,dx
  160.         mov     eax,oldint9
  161.         mov     fs:[9*4],eax
  162.         sti
  163.         pop     fs
  164.         ret
  165. killkeyboard    endp
  166. ────────────────────────────────────────────────────────────────────────────────
  167. timer           proc    near
  168.         push    ax
  169.         mov     al,20h
  170.         out     20h,al
  171.         inc     cs:counter
  172.         inc     cs:int_1ch
  173.         cmp     cs:int_1ch,22
  174.         jb      no_int_1ch
  175.         mov     cs:int_1ch,00
  176.         int    1ch
  177. no_int_1ch:     pop     ax
  178.         iret
  179. counter         dw      0
  180. int_1ch         db      0
  181. timer           endp
  182. ────────────────────────────────────────────────────────────────────────────────
  183. inittimer       proc    near
  184.         cli
  185.         push    gs
  186.         xor     dx,dx
  187.         mov     gs,dx
  188.         mov     eax,gs:[8*4]
  189.         mov     oldint8,eax
  190.         mov     ax,cs
  191.         shl     eax,16
  192.         mov     ax,offset timer
  193.         mov     dx,2841             ; ∙ 140 Hz double Screen Sync
  194.         mov     gs:[8*4],eax
  195.  
  196. out_it:         mov     al,036h                 ; ∙ out these things, they
  197.         out     43h,al                  ;   just remain a secret
  198.         mov     al,dl                   ;   for me...
  199.         out     40h,al
  200.         mov     al,dh
  201.         out     40h,al
  202.         sti
  203.         pop     gs
  204.         ret
  205. inittimer       endp
  206. ────────────────────────────────────────────────────────────────────────────────
  207. killtimer       proc near
  208.         push    gs
  209.         xor     dx,dx
  210.         mov     gs,dx
  211.         cli
  212.         mov     eax,oldint8
  213.         mov     gs:[8*4],eax
  214.         jmp     out_it
  215. killtimer       endp
  216. ────────────────────────────────────────────────────────────────────────────────
  217. initvideo    proc    near
  218.          call    zeropalette
  219.         mov    ax,13h
  220.         int    10h
  221.         call    zeropalette
  222.         vsync
  223.  
  224.         mov    dx,3c0h
  225.         mov    al,30h
  226.         out    dx,al
  227.         mov    al,01100001b
  228.         out    dx,al
  229.         mov    dx,3c4h            ; ∙ unchain mode!
  230.         mov    ax,604h
  231.         out    dx,ax
  232.         mov    dx,3d4h            ; ∙ four chain mode
  233.         mov    ax,14h
  234.         out    dx,ax
  235.         mov    ax,0e317h
  236.         out    dx,ax
  237.         mov    dx,3c4h            ; ∙ all planes
  238.         mov    ax,0f02h
  239.         out    dx,ax
  240.         mov    dx,3ceh            ; ∙ bitmasking
  241.         mov    ax,0ff08h
  242.         out    dx,ax
  243.  
  244.         push    @data
  245.         pop    ds
  246.         push    0a000h
  247.         pop    es
  248.         xor    di,di
  249.         xor    eax,eax
  250.         mov    cx,8000h/2
  251.         rep    stosd            ; ∙ clear screen
  252.         call    setpalette
  253.         ret
  254. initvideo    endp
  255. ────────────────────────────────────────────────────────────────────────────────
  256. killvideo    proc    near
  257.         mov     ah,12h              ; ∙ restore palette
  258.         mov     bl,31h
  259.         mov     al,00h
  260.         int     10h
  261.  
  262.         mov     ax,0003h        ; ∙ text mode!
  263.         int     10h
  264.         ret
  265. killvideo    endp
  266. ────────────────────────────────────────────────────────────────────────────────
  267. zeropalette    proc    near
  268.         mov     dx,03c8h                ; ∙ port PEL write mode
  269.         mov     al,00h                  ;   at register 00h
  270.         out     dx,al
  271.         xor    al,al
  272.         inc     dx                      ; ∙ port PEL data register
  273.         mov     cx,0100h*3
  274. @clear:        out    dx,al
  275.         loop    @clear
  276.         ret
  277. zeropalette    endp
  278. ────────────────────────────────────────────────────────────────────────────────
  279. setpalette     proc    near
  280.         mov     si,offset vgapalette
  281.         mov     dx,03c8h                ; ∙ port PEL write mode
  282.         mov     al,00h                  ;   at register 00h
  283.         out     dx,al
  284.         inc     dx                      ; ∙ port PEL data register
  285.         mov     cx,0100h*3
  286.         rep     outsb
  287.         ret                             ; ∙ vga color a 100h times
  288. setpalette    endp
  289. ────────────────────────────────────────────────────────────────────────────────
  290. ; =======================================
  291. ; Arrrrgghhhhhhh!!! So many comments!! %-P
  292. ; Can't bear it: I know how it works, I intended
  293. ; to do it just this way, messy as it looks.
  294.  
  295. GenerateLand:
  296.         push    es
  297.         MOV     CX,320                  ; This many points to generate.
  298.         MOV     SI,OFFSET LastLine      ; Last line is in SI.
  299.         MOV     DI,OFFSET ThisLine      ; New values in DI.
  300.  
  301.         MOV     DX,[SI+319*2]   ; DX will mean height of the (X-1) point.
  302.                                 ; We need a starting value for it, so...
  303.     @@l1:
  304.         PUSH    CX
  305.         call    Random
  306.         AND     AX,4*1024-1     ; 0 <= AX <= 4*1024-1
  307.         ADD     AX,AX           ; 0 <= AX <= 8*1024-2
  308.  
  309.         MOV     BX,[DI]
  310.         SUB     BX,[DI-2]       ; Get horiz. slope of prev. line.
  311.         JNC     @@up            ; If it was negative ( -> down) we'll go up.
  312.      @@dn:                      ; -3*1024 < AX < 5*1024. A neat trick here:
  313.          SUB    AX,3*1024-3     ; -3 => A global tendency upwards.
  314.          JMP    @@put           ;   The top limit will do the rest. It works!
  315.      @@up:
  316.          SUB    AX,5*1024-1     ; If it was positive ( -> up) we'll go down.
  317.                                 ; -5*1024 < AX < 3*1024. No tricks now.
  318.      @@put:                             
  319.          MOV    BP,DX           ; DX is (X-1) height. Save in BP.
  320.                                 ; AX is horiz. slope.
  321.          ADD    AX,DX           ; Create new height.
  322.          
  323.          CMP    BP,8000         ; Detect overflow. Quite shitty, but works.
  324.          JNC    @@chk0          ; If height of X-1 was below 8000 and
  325.           CMP   AX,65536-8000   ; new height is above 65536-8000 (or
  326.           JC    @@ok0           ; viceversa), there has been a rollover.
  327.            MOV  AX,BP           ; In that case, stick to height of X-1.
  328.            JMP  @@ok0
  329.     @@chk0:
  330.          CMP    BP,65536-8000   ; Here comes the viceversa. ;-)
  331.          JC     @@ok0
  332.           CMP   AX,8000
  333.           JNC   @@ok0
  334.            MOV  AX,BP           ; In that case, stick to height of X-1.
  335.       @@ok0:
  336.  
  337.          MOV    BX,[SI+2]       ; Now average height with previous line.
  338.          ADD    BX,[SI+4]       ; X+1 & X+2 seem to avoid diagonals.
  339.          RCR    BX,1
  340.          ADD    AX,BX
  341.          RCR    AX,1
  342.          
  343.          CMP    AX,[HLimit]     ; Absolute maximum.
  344.          JC     @@notop
  345.           MOV   AX,BP ;[HLimit]
  346.      @@notop:
  347.  
  348.          MOV    [DI],AX         ; Store new height, and save in DX for X+1.
  349.          MOV    BP,DX
  350.          MOV    DX,AX
  351.  
  352.     @@dofilter:
  353.          ADD    AX,[DI+320*2*2] ; Filter height value for screen color.
  354.          RCR    AX,1
  355.          MOV    BX,[LastValue]  ; This will make the landscape look nicer.
  356.          ADD    AX,BX
  357.          RCR    AX,1
  358.  
  359.    @@setval:
  360.          MOV    [DI+320*2*2],AX ; Store the screen values, at last...
  361.          MOV    [LastValue],AX
  362.  
  363.          ADD    DI,2            ; Now, do the usual loop arrangements.
  364.          ADD    SI,2
  365.          POP    CX
  366.          DEC    CX
  367.          JNZ    SMALL @@l1
  368.  
  369.  
  370.         MOV     AX,DS           ; Now copy buffers to nice positions.
  371.         MOV     ES,AX           ; No more comments from now on.
  372.  
  373.         MOV     DI,OFFSET LastLine
  374.         MOV     SI,OFFSET ThisLine
  375.         MOV     CX,320/2
  376.         REP MOVSD
  377.  
  378.         MOV     DI,OFFSET LastLine-160*2
  379.         MOV     SI,OFFSET LastLine+160*2
  380.         MOV     CX,160/2
  381.         REP MOVSD
  382.         MOV     DI,OFFSET LastLine+320*2
  383.         MOV     SI,OFFSET LastLine
  384.         MOV     CX,160/2
  385.         REP MOVSD
  386.  
  387.         pop    es
  388.         RET
  389. ────────────────────────────────────────────────────────────────────────────────
  390.  
  391. ; =======================================
  392.  
  393. DumpLandLine:
  394.         MOV     DX,3CEh                 ; Bitmask...
  395.         MOV     AX,0FF08h               ; 11111111b
  396.         OUT     DX,AX
  397.  
  398.         MOV     SI,OFFSET  DrawLine+1  ; ThisLine+1
  399.         MOV     AX,102h
  400.     @@l1:
  401.         PUSH    AX
  402.         MOV     DX,3C4h
  403.         OUT     DX,AX
  404.  
  405.         MOV     DI,[ScrollPos]
  406.         MOV     CX,SCRWidth/2
  407.     @@l2:
  408.          MOV    AL,[SI]
  409.          MOV    AH,[SI+8]
  410.          MOV    ES:[DI+201*SCRWidth],AX
  411.          MOV    ES:[DI+402*SCRWidth],AX
  412.          STOSW
  413.          ADD    SI,16
  414.          LOOP   @@l2
  415.  
  416.         SUB     SI,16*SCRWidth/2-2
  417.         POP     AX
  418.         SHL     AH,1
  419.         JNC     @@l1
  420.  
  421.         RET
  422. ────────────────────────────────────────────────────────────────────────────────
  423. initland    proc    near
  424.         push    es
  425.         push    ds
  426.         pop    es
  427.         mov    ax,initheight
  428.         mov    di,offset initinitial
  429.         mov    cx,(offset endinitial-offset initinitial)/2
  430.         rep    stosw
  431.         xor    ax,ax
  432.         mov    di,offset initzero
  433.         mov    cx,(offset endzero-offset initzero)/4
  434.         rep    stosd
  435.         pop    es
  436.         ret
  437. initland    endp
  438. ────────────────────────────────────────────────────────────────────────────────
  439. doframing    proc    near
  440.         inc    framenumber
  441.         ret
  442. doframing    endp
  443. ────────────────────────────────────────────────────────────────────────────────
  444. checkheight    proc    near
  445.         cmp    framenumber,250
  446.         jc    carry2
  447.         add    hlimit,50h
  448.         cmp    hlimit,0f000h
  449.         jc    carry3
  450.         mov    hlimit,0f000h
  451.         jmp    carry3
  452. carry2:        add    hlimit,1000h/250*2
  453. carry3:        ret
  454. checkheight    endp
  455. ────────────────────────────────────────────────────────────────────────────────
  456. movelandline    proc    near
  457.         cli
  458.         mov    bx,[scrollpos]
  459.         mov    dx,03d4h
  460.         mov    al,0ch
  461.         mov    ah,bh
  462.         out    dx,ax            ; ∙ high byte
  463.         inc    al
  464.         mov    ah,bl
  465.         out    dx,ax            ; ∙ low byte
  466.         sti
  467.  
  468.         sub    scrshown,scrwidth
  469.         sub    scrnext,scrwidth
  470.         sub    bx,scrwidth
  471.         jnc    @@okay
  472.         add    bx,201*scrwidth
  473.         add    scrshown,201*scrwidth
  474.         add    scrnext,201*scrwidth
  475. @@okay:        mov    scrollpos,bx
  476.         ret
  477. movelandline    endp
  478. ────────────────────────────────────────────────────────────────────────────────
  479. savescreen    proc    near
  480.         push    ds
  481.         push    seg screen
  482.         pop    ds
  483.         mov    si,scrshown
  484.         mov    di,offset screen
  485.         mov    cx,320*200
  486. @saveit:    mov    bx,si
  487.         mov     al,04                   ; ∙ read mask
  488.         mov     ah,bl                   ; ∙ x position
  489.         and     ah,3
  490.         mov     dx,3ceh
  491.         out     dx,ax
  492.         shr    bx,2
  493.         mov     al,es:[bx]
  494.         mov    [di],0
  495.         inc    di
  496.         inc    si
  497.         loop    @saveit
  498.  
  499.         mov    bx,[scrollpos]
  500.         mov    dx,03d4h
  501.         mov    al,0ch
  502.         mov    ah,00
  503.         out    dx,ax            ; ∙ high byte
  504.         inc    al
  505.         mov    ah,00
  506.         out    dx,ax            ; ∙ low byte
  507.  
  508.         mov    dx,3d4h            ; ∙ four chain mode
  509.            mov    ax,14h*2
  510.            out    dx,ax
  511.            mov    ax,0e317h
  512.            out    dx,ax
  513.         mov    ax,01340h
  514.         out    dx,ax
  515.  
  516.         mov    si,offset screen
  517.         mov    di,0
  518.         mov    cx,320*200/4
  519.         rep    movsd
  520.         pop    ds
  521.         ret
  522. savescreen    endp
  523. ────────────────────────────────────────────────────────────────────────────────
  524. random        proc    near
  525.         mov    ax,randseed1
  526.         mov    bx,randseed2
  527.         add    ax,0a137h
  528.         add    bx,063f7h
  529.         rol    ax,2
  530.         mov    randseed1,ax
  531.         add    bx,ax
  532.         ror    bx,1
  533.         mov    randseed2,bx
  534.         add    ax,bx
  535.         ret
  536. random        endp
  537. ────────────────────────────────────────────────────────────────────────────────
  538. displaylogo    proc    near
  539.         cmp    framenumber,1615
  540.         jb    skip
  541.         cmp    logopos,0
  542.         je    skip
  543.         mov    di,offset drawline+1+32*2
  544.         mov    si,offset vgalogo
  545.         add    si,logopos
  546.         mov    cx,256
  547. invert:        mov    al,[si]
  548.         cmp    al,00
  549.         je    noinv1
  550.         add    byte ptr [di],38
  551. noinv1:        inc    si
  552.         inc    di
  553.         inc    di
  554.         loop    invert
  555.         sub    logopos,256
  556. skip:        ret
  557. displaylogo    endp
  558. ────────────────────────────────────────────────────────────────────────────────
  559. main:        call    inittimer
  560.         call    initkeyboard
  561.         call    initvideo
  562.         call    initland
  563.         call    ega2vga
  564. scape:         vsync
  565.         call    doframing
  566.         call    displaylogo
  567.         call    dumplandline
  568.         call    checkheight
  569.         call    movelandline
  570.         call    generateland
  571.         call    checkkey
  572.         cmp    framenumber,1750;      1335
  573.         jb    scape
  574.         vsync
  575.         call    blendout
  576.         vsync
  577.         ;call    savescreen
  578.         call    blendin
  579. warp:        vsync
  580.         call    doframing
  581.         call    checkkey
  582.         jmp    warp
  583.  
  584. exit:       call    zeropalette
  585.         call    killvideo
  586.         call    killkeyboard
  587.         call    killtimer
  588.         mov    ax,4c00h
  589.         int    21h
  590. ────────────────────────────────────────────────────────────────────────────────
  591. .data
  592. oldint9         dd      ?
  593. oldint8         dd      ?
  594.  
  595. randseed1    dw    348bh
  596. randseed2    dw    7f34h
  597.  
  598. logopos        dw    256*84
  599. scrollpos    dw    0        ; ∙ memory offset of upper line.
  600. scrshown    dw    0            ; ∙ base offset of currently screen
  601. scrnext        dw    201*scrwidth    ; ∙ "      "    of updating screen
  602. include        fire.pal
  603. include        f-scape.dat
  604. ────────────────────────────────────────────────────────────────────────────────
  605. udataseg
  606. initinitial    label     word
  607. lastvalue    dw    ?
  608. lastvalue2    dw    ?
  609.  
  610.         dw    160 dup (?)
  611. lastline    dw    320 dup (?)
  612.         dw    160 dup (?)
  613. endinitial     label    word
  614.  
  615. initzero       label    word
  616. vgalogo        db    256*85 dup (?)
  617.  
  618. thisline    dw    320 dup (?)
  619. slopes        dw    320 dup (?)
  620. drawline    dw    320 dup (?)
  621.  
  622. updatescr    dw    ?
  623.  
  624. framenumber    dd    ?
  625. hlimit        dw    ?
  626. lastslope    dw    ?
  627. endzero        label    word
  628. ────────────────────────────────────────────────────────────────────────────────
  629. .fardata
  630. screen        db    320*200 dup (?)
  631. ────────────────────────────────────────────────────────────────────────────────
  632. end
  633.